﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MagicArena.framework.toon;
using MagicArena.framework.state;
using Microsoft.Xna.Framework;

namespace MagicArena.framework.graphics
{
    public abstract class ARenderer : IToonComponent, IUpdateable
    {
        protected Toon Source
        {
            private set;
            get;
        }

        protected ARenderer()
        {
            //TODO get nessasary components from Toon 
        }

        protected abstract void Render();

        public virtual void AttachToToon(Toon t)
        {
            Source = t;
        }


        #region IUpdatable methods
        #region Enable
        private bool _Enabled = false;
        public bool Enabled
        {
            get { return _Enabled; }
            set
            {
                if (_Enabled != value)
                {
                    _Enabled = value;
                    OnEnabledChanged(new EnabledEventArgs(value));
                }
                _Enabled = value;
            }
        }

        public event EventHandler<EventArgs> EnabledChanged;

        public class EnabledEventArgs : EventArgs
        {
            public bool NewState
            {
                get;
                private set;
            }
            public EnabledEventArgs(bool state)
            {
                NewState = state;
            }
        }
        protected virtual void OnEnabledChanged(EventArgs e)
        {
            if (EnabledChanged != null) EnabledChanged(this, e);
        }
        #endregion

        #region Update
        public abstract void Update(GameTime gameTime);

        public int UpdateOrder
        {
            get { return Int16.MaxValue / 2; }
        }

        public event EventHandler<EventArgs> UpdateOrderChanged;
        #endregion
        #endregion

    }
}
